package com.tuyue.police.biz.impl;

import com.tuyue.police.biz.IDispatcherBiz;
import com.tuyue.police.dao.*;
import com.tuyue.police.pojo.DispenseWay;
import com.tuyue.police.pojo.Rule;
import com.tuyue.police.pojo.Sector;
import com.tuyue.police.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/3/16.
 * @Modified By:
 */
@Component
@Slf4j
public class DispatcherBizImpl implements IDispatcherBiz {

    @Autowired
    private IRuleDao ruleDao;
    @Autowired
    private IRule1Dao rule1Dao;
    @Autowired
    private IRule2Dao rule2Dao;
    @Autowired
    private IUserDao userDao;
    @Autowired
    private IDispenseWayDao dispenseWayDao;

    @Override
    public void dispatcher(Sector sector) {

        List<Rule> ruleList = ruleDao.findAllBySectorId(sector.getSectorId());
        if (ruleList.size()>0) {
            for (Rule rule : ruleList) {
                DispenseWay dispenseWay = dispenseWayDao.findOne(rule.getRuleDispenseId());
                List<User> userList = userDao.findAllByRuleId(rule.getRuleId());
                if (dispenseWay==null) {
                    return;
                }
                switch (dispenseWay.getDispenseName()) {
                    case "ys":
                        userList.forEach(user -> {
                            log.info("APP推送成功,推送用户:{}",user.getUserName());
                        });
                        break;
                    case "短信":
                        userList.forEach(user -> {
                            log.info("短信推送成功,推送用户:{}",user.getUserName());
                        });
                        break;
                    case "公众号":
                        userList.forEach(user -> {
                            log.info("公众号推送成功,推送用户:{}",user.getUserName());
                        });
                        break;
                    default:
                        log.info("没有分发规则");
                        break;
                }
            }
        }

        log.info("没有分发规则");

    }


}
